package milkyway.hightech.money;

import java.math.BigDecimal;

/**
 *
 * @author michael
 */
public class Convert
{
    /**
     *
     * @param money
     * @param currency
     * @return
     */
    public static Money convert(Money money, Currency currency)
    {
        money = convertToBaseCurrency(money);

        double factor = currency.getFactor();
        BigDecimal d = new BigDecimal(money.getValue());

        d = d.multiply((BigDecimal.valueOf(factor)));

        return new Money(d.toBigInteger(), currency);
    }

    /**
     *
     * @param money
     * @return
     */
    private static Money convertToBaseCurrency(Money money)
    {
        double factor = 1 / money.getCurrency().getFactor();
        BigDecimal d = new BigDecimal(money.getValue());

        d = d.multiply(BigDecimal.valueOf(factor));

        return new Money(d.toBigInteger(), Currency.EUR);
    }
}